package com.gitee.hljdrl.dsbridge.jsapi;

import android.content.Context;
import android.util.Log;

import androidx.annotation.Keep;

import com.gitee.hljdrl.dsbridge.basis.WebViewEvent;

@Keep
public abstract class DSPlugin {

    protected final String TAG = getClass().getSimpleName();

    private Context mContext;
    protected WebViewEvent mWebViewEvent;

    public final void setWebViewEvent(WebViewEvent webViewEvent) {
        this.mWebViewEvent = webViewEvent;
    }

    protected final WebViewEvent getWebViewEvent() {
        return mWebViewEvent;
    }

    protected final DSPlugin findDSPlugin(String name) {
        if (mWebViewEvent != null) {
            return mWebViewEvent.findDSPlugin(name);
        }
        return null;
    }

    public void onCreate(Context context) {
        mContext = context;
    }

    protected Context getContext() {
        return mContext;
    }

    public void onPause() {

    }

    public void onResume() {

    }

    public void onDestroy() {

    }

    public void onLoadUrlBefore(String url) {

    }

    public final boolean isDebug() {
        if (mWebViewEvent != null) {
            return mWebViewEvent.isDebug();
        }
        return false;
    }

    public final void executeScript(final String script) {
        if (mWebViewEvent != null) {
            mWebViewEvent.executeScript(script);
        } else {
            Log.e(TAG, "executeScript WebViewEvent=NULL error");
        }
    }


}
